<template>
	<view class="page">
		<!-- 商家核销记录 -->
		<view class="content-box" v-if="type == 0">
			<view class="item-label" v-for="item in list" :key="item.id">
				<view class="left-num">{{ '-' + item.haoren_number }}</view>
				<view class="right-time">{{ item.times  }}</view>
			</view>
		</view>
		<!-- 用户核销记录 -->
		<view class="content-box" v-if="type == 1">
			<view class="item-label" v-for="item in list" :key="item.id">
				<view class="left-num">{{ item.createtime }}</view>
				<view class="right-time">{{ item.money }}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				limit: 15,
				list: [],
				total: 0,
				type: 0
			}
		},
		onLoad(option) {
			if(option.type == 1) { this.type = 1, this.userInit() }
			else this.init()
		},
		methods: {
			// 商家好人值记录
			init() {
				let { page, limit, total } = this;
				let to_shop_id = uni.getStorageSync('userShopId');
				this.$api.post({
					url: '/wanlshop.shop/shopHaorenList',
					data: { to_shop_id, page, limit },
					success: res => {
						uni.hideLoading()
						this.total = res.total;
						this.list.push(...res.list)
					}
				})
			},
			
			//用户好人值记录
			userInit() {
				let { page, limit } = this;
				this.$api.post({
					url: '/user/haorenLog',
					data: { page, limit },
					success: res => {
						uni.hideLoading()
						this.total = res.count
						this.list.push(...res.list)
					}
				})
			},
		},
		onReachBottom() {
				uni.showLoading()
				let { list, total, type } = this;
				if(list.length < total) {
					++this.page;
					if(type == 1) this.userInit()
					else this.init();
				} else {
					uni.hideLoading()
					uni.showToast({
						title: "没有更多了",
						icon: 'none'
					})
				}
			}
	}
</script>

<style scoped>
.page {
	background-color: white;
}
.content-box {
	display: flex;
	width: 100%;
	flex-direction: column;
}
.item-label {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
	padding: 45rpx 35rpx;
	border-bottom: solid 1rpx #EFEFEF;
	box-sizing: border-box;
}
.left-num {
	font-size: 32rpx;
	font-weight: bold;
	color: #FF3C00;
}
.right-time {
	font-size: 28rpx;
	color: #999999;
	line-height: 28rpx;
}
</style>
